package me.thinkjet.controller;

import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import me.thinkjet.model.Area;
import me.thinkjet.service.UploadService;

import java.io.File;
import java.util.List;

@ControllerBind(controllerKey = "/area", viewPath = "")
public class AreaController extends Controller {

	public void index() {
		int parent = getParaToInt() == null ? 0 : getParaToInt();
		List<Area> areas = Area.dao.find("select id,name from area where parent=?", parent);
		StringBuilder sb = new StringBuilder();
		sb.append("[");
		sb.append("[\"0\",\"全部\"]");
		for (Area a : areas) {
			sb.append(",[\"" + a.get("id") + "\"," + "\"" + a.get("name") + "\"]");
		}
		sb.append("]");
		renderJson(sb.toString());
	}

	public void hot() {
		setAttr("area", Area.dao.find("select * from area where hot=1 limit 0,10"));
		this.renderJson();
	}
}
